import { CrudOptions, AddReq, DelReq, EditReq, dict, CrudExpose, UserPageQuery, CreateCrudOptionsRet} from '@fast-crud/fast-crud';
import * as _ from 'lodash-es';
import * as api from './api';
import { request } from '/@/utils/service';
import { dictionary } from '/@/utils/dictionary';
import {inject} from "vue";


//此处为crudOptions配置
export default function ({ crudExpose}: { crudExpose: CrudExpose}): CreateCrudOptionsRet {
	const pageRequest = async (query: any) => {
		return await api.GetList(query);
	};
	const editRequest = async ({ form, row }: EditReq) => {
		if (row.id) {  
			form.id = row.id;
		}
		return await api.UpdateObj(form);
	};
	const delRequest = async ({ row }: DelReq) => {
		return await api.DelObj(row.id);
	};
	const addRequest = async ({ form }: AddReq) => {
		return await api.AddObj(form);
	};

    const exportRequest = async (query: UserPageQuery) => {
		return await api.exportData(query)
	};

		

	return {
		crudOptions: {
			request: {
				pageRequest,
				addRequest,
				editRequest,
				delRequest,
			},
			viewForm: {
				wrapper: {
					buttons: {
						ok: { show: false },
						cancel: { show: false },
						reset: { show: false },
					},
				},
			},
			columns: {
                class: {
                    title: 'Service Classes',
                    children: {
                        title: {
                            title: 'Class',
                            type: 'input',
                        },
                        name: {
                            title: 'Description',
                            type: 'input',
                        },
                    },
                },
				downtime: {
					title: 'Unplan Downtime(Machine Room Not Failure)',
					children: {
                        downtime_level: {
                            title: 'Service Levels',
                            type: 'input',
                            mixWith: 100,
                        },
                        downtime_service: {
                            title: 'Services',
                            type: 'input',
                        }
                    },
				},
				disaster: {
					title: 'Disaster(Machine Room Failure)',
					children: {
                        disaster_level: {
                                title: 'Service Levels',
                                type: 'input',
                        },
                        disaster_service: {
                            title: 'Services',
                            type: 'input',
                        },
                    },
				},
				remark: {
					title: '备注',
					type: 'input',
					search: { show: false},
					column: {
						// minWidth: 120,
						sortable: false,
					},
					form: {
						component: {
							placeholder: '',
						},
					}
				},
				update_datetime: {
					title: '更新时间',
					type: 'datetime',
					search: { show: false },
					column: {
						//minWidth: 200,
						sortable: 'custom',
					},
					form: {
						show: false
					},
				},
			},
		},
	};
}
